using System.Linq;

namespace TelerikMvcGridCustomBindingHelper
{
    public class GridQueryProvider
    {
        private readonly IGridDataService _service;
        public readonly IQueryable Query;
        public readonly IQueryable QueryToCountData;

        public GridQueryProvider(IGridDataService service)
        {
            _service = service;
            Query = _service.GetQuery();
            QueryToCountData = _service.GetQuery(true);
        }

        public GridQueryProvider(IQueryable query, IQueryable queryToCountData = null)
        {
            Query = query;
            QueryToCountData = queryToCountData ?? query;
        }

        public IQueryable<TEntity> GetQuery<TEntity>(bool onlyForCount = false)
        {
            return onlyForCount
                ? (IQueryable<TEntity>)QueryToCountData
                : (IQueryable<TEntity>)Query;
        }
    }
}